package c3.Demo03;

/**
 * 1.  this 关键字
 *  student区间内 this指类本身
 *     使用this可以使用类的其他属性和方法
 * 2.  static 关键字
 */
class Student{
    String id;
    String name;
    private int age;
    private int gender;// 0男 1女
    String dep = "信息系";
    static  String hobby = "健身";

    public  Student(String ID){// 方法名称和类名一致 叫做构造方法
        id = ID;

    }

    public Student(){

    }
    void read(){
        System.out.println("大家好，我是"+name+"，我在看书");
    }
    void setAge(int age){//设置年龄
        // this.age = age;// student区间内 this指类本身
        if(age < 0  || age > 150){
            System.out.println("您输入的年龄有误");
        }else{
            this.age = age;
        }
    }

    int getAge(){//获取年龄
        return age;
    }
    // 转化性别汉字到数字
    void setGender(String g){
        if (g.equals("男")){// String类型判断字符相等固定格式
            gender=0;
        }else if(g.equals("女")){
            gender=1;
        }else{
            System.out.println("性别有误");
        }
    }
    String getGender(){
        if(gender ==0){
            return "男";
        }else{
            return "女";
        }
    }
}
public class Demo03 {
    public static void main(String[] args) {
        Student stu1 = new Student();
        stu1.setAge(18);
        Student stu2 = new Student();
        System.out.println(stu1.dep);
        System.out.println(stu2.dep);
        stu1.dep = "宇宙系";
        System.out.println("修改stu1后的系部信息");
        System.out.println(stu1.dep);
        System.out.println(stu2.dep);
        System.out.println("******");
        System.out.println(stu1.hobby);
        System.out.println(stu2.hobby);
        stu1.hobby = "抽烟";
        System.out.println("学生1爱好static属性变化");
        System.out.println(stu1.hobby);
        System.out.println(stu2.hobby);
    }
}
